﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Framework.Common;
using Framework.Common.Paged;
using Framework.Core;
using YouTravel.DomainService;
using YouTravel.Framework.Enums;
using YouTravel.Framework.ResourceMessage;
using YouTravel.QueryModels;
using YouTravel.ViewModels;

namespace Application.WebAPI.Controllers
{
    /// <summary>
    /// 收款
    /// </summary>
    [RoutePrefix("api/gathering")]
    public class GatheringController : BaseController
    {
        readonly IGatheringService _gatheringService;
        readonly DataResult _dataResult = new DataResult();
        public GatheringController(IGatheringService gatheringService)
        {
            this._gatheringService = gatheringService;
        }
        /// <summary>
        /// 申请提交收款
        /// </summary>
        /// <param name="gathering"></param>
        /// <returns></returns>
        [HttpPost, Route("submitgathering"), AuthorityVerify(AuthorityRole.SpecialLineAdministrator, AuthorityRole.SpecialLineOperator)]
        public HttpResponseMessage SubmitGathering(GatheringViewModel gathering)
        {
            _gatheringService.SubmitGathering(gathering, LoginUser.ID);
            _dataResult.Code = ResponseStatusCode.Success;
            _dataResult.Msg = BusinessResourceMessage.Success;
            return Request.CreateResponse(HttpStatusCode.OK, _dataResult);
        }
        /// <summary>
        /// 审核提交收款信息
        /// </summary>
        /// <param name="gathering"></param>
        /// <returns></returns>
        [HttpPost, Route("auditgathering"), AuthorityVerify(AuthorityRole.Branch)]
        public HttpResponseMessage AuditGathering(GatheringViewModel gathering)
        {
            _gatheringService.AuditGathering(gathering, LoginUser.ID);
            _dataResult.Code = ResponseStatusCode.Success;
            _dataResult.Msg = BusinessResourceMessage.Success;
            return Request.CreateResponse(HttpStatusCode.OK, _dataResult);
        }

        /// <summary>
        /// 得到收款详细
        /// </summary>
        /// <param name="gathering"></param>
        /// <returns></returns>
        [HttpPost, Route("getmodel"), AuthorityVerify(AuthorityRole.Branch, AuthorityRole.SpecialLineAdministrator, AuthorityRole.SpecialLineOperator)]
        public HttpResponseMessage GetModel(GatheringViewModel gathering)
        {
            _dataResult.Code = ResponseStatusCode.Success;
            _dataResult.Msg = BusinessResourceMessage.Success;
            _dataResult.Data = _gatheringService.GetModel(gathering.ID, LoginUser.ID);
            return Request.CreateResponse(HttpStatusCode.OK, _dataResult);
        }
        /// <summary>
        /// 得到收款列表
        /// </summary>
        /// <param name="queryCond"></param>
        /// <returns></returns>
        [HttpPost, Route("getlist"), AuthorityVerify(AuthorityRole.Branch, AuthorityRole.SpecialLineAdministrator, AuthorityRole.SpecialLineOperator)]
        public HttpResponseMessage GetList(PagedParam<GatheringQuery> queryCond)
        {
            queryCond.QueryDto.LoginUserId = LoginUser.ID;
            _dataResult.Code = ResponseStatusCode.Success;
            _dataResult.Msg = BusinessResourceMessage.Success;
            _dataResult.Data = _gatheringService.GetList(queryCond);
            return Request.CreateResponse(HttpStatusCode.OK, _dataResult);
        }
    }
}
